#include "imageinfo.h"

ImageInfo::ImageInfo() {}

bool ImageInfo::writeXML(const QXmlStreamWriter &writer){
    return true;
}

bool ImageInfo::ReadXML(QXmlStreamReader &reader){
    QXmlStreamAttributes attributes = reader.attributes();

    QXmlStreamReader::TokenType token = reader.readNext();
    while (!(reader.tokenType() == QXmlStreamReader::EndElement &&
             reader.name() == QStringLiteral("imageInfo"))) {

        if (reader.name() == QStringLiteral("imageWidth")) {
            m_nImageWidth = reader.readElementText().toInt();
        }else if (reader.name() == QStringLiteral("imageHeight")) {
            m_nImageHeight = reader.readElementText().toInt();
        }else if (reader.name() == QStringLiteral("imageChannel")) {
            m_nImageChannel = reader.readElementText().toInt();
        }

        reader.readNext();
    }
    return true;
}

QJsonObject ImageInfo::toJson(){
    QJsonObject obj;
    obj["imageWidth"] = this->m_nImageWidth;
    obj["imageHeight"] = this->m_nImageHeight;
    obj["imageChannel"] = this->m_nImageChannel;
    return obj;
}

void ImageInfo::fromJson(QJsonObject obj){
    this->m_nImageWidth = obj["imageWidth"].toInt();
    this->m_nImageHeight = obj["imageHeight"].toInt();
    this->m_nImageChannel = obj["imageChannel"].toInt();
}
